package com.example.nyf.mapper;

import com.example.nyf.dto.SysMenuDTO;
import com.example.nyf.entity.SysMenu;
import com.example.nyf.mapper.provider.SysMenuProvider;
import com.example.nyf.mapper.provider.SysUserProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface SysMenuMapper {

    @Select("select * from sys_menu a " +
            "left join sys_role_menu b on a.id = b.menu_id " +
            "left join sys_user_role c on b.role_id = c.role_id " +
            "left join sys_role d on c.role_id = d.id " +
            "where c.user_id = #{user_id}")
    public List<SysMenu> listSysMenuByUserId(@Param("user_id") Integer user_id);

    @SelectProvider(type = SysMenuProvider.class, method = "listSysMenu")
    public List<SysMenu> listSysMenu(Map mp);

    @Select("select * from sys_menu where parent_id = #{parent_id}")
    public List<SysMenu> listSysMenuAll(@Param("parent_id") Integer parent_id);

    @Select("select id, menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, " +
            "remark, add_user_id, add_user_name, add_time  from sys_menu where id = #{id}")
    public SysMenu getSysMenuById(@Param("id") Integer id);

    @Select("select id, menu_name, parent_id, order_num, url, menu_type, visible, perms, icon, " +
            "remark, add_user_id, add_user_name, add_time  from sys_menu where parent_id = 0")
    public List<SysMenu> listSysMenuTop();


    @InsertProvider(type = SysMenuProvider.class, method = "insertSysMenu")
    public int insertSysMenu(SysMenu sysMenu);

    @Update({"update sys_menu set menu_name = #{menu_name}, parent_id = #{parent_id}" +
            ", order_num = #{order_num}, url = #{url}, menu_type = #{menu_type}" +
            ", perms = #{perms}, icon = #{icon}, remark = #{remark}" +
            " where id = #{id}"})
    public int updateSysMenu(SysMenu sysMenu);

    @Delete("delete from sys_menu where id = #{id}")
    public int deleteSysMenu(@Param("id") Integer id);
}
